package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.dto.Result;
import tech.aistar.dto.Urankinfo;
import tech.aistar.entity.Urank;
import tech.aistar.entity.User;
import tech.aistar.service.impl.LevelServiceImpl;
import tech.aistar.service.impl.UrankServiceImpl;
import tech.aistar.service.impl.UserServiceImpl;

import javax.servlet.http.HttpSession;
import java.util.Comparator;
import java.util.List;

@Controller
@RequestMapping("/rank")
public class UrankAction {
    @Autowired
    private UrankServiceImpl urankService;
    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private LevelServiceImpl levelService;
    @RequestMapping("/load")
    public String load(HttpSession session, Model model){
        model.addAttribute("java",urankService.findScore());
        model.addAttribute("python",urankService.findScore1());
        model.addAttribute("c",urankService.findScore2());
        model.addAttribute("web",urankService.findScore3());
        model.addAttribute("sql",urankService.findScore4());
       return "rank";
    }
    @RequestMapping("/userinfo")
    public @ResponseBody User userinfo(@RequestParam("nickname") String nickname){
        System.out.println("1230"+nickname);
//        System.out.println(model.getAttribute("nickname"));
        return userService.findUserBynickname(nickname);
    }

}
